package com.shigen.file.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shigen.file.common.Result;
import com.shigen.file.req.ProjectDataRequest;
import com.shigen.file.req.ProjectDataRequest.PageRequest;
import com.shigen.file.service.IProjectDataService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 表单的数据 前端控制器
 * </p>
 *
 * @author shigen.fu
 * @since 2022-06-04
 */
@RestController
@RequestMapping("/projectData")
public class ProjectDataController {

  @Resource
  private IProjectDataService projectDataService;

  /**
   * 分页查询
   */
  @PostMapping(value = "page")
  public Result<IPage<JSONObject>> getProjectData(@RequestBody @Valid PageRequest pageRequest) {
    IPage<JSONObject> projectData = projectDataService.getProjectData(pageRequest.getProjId(), pageRequest.getWithAdditionInfo(), new Page<>(pageRequest.getPagenum(), pageRequest.getPagesize()));
    return Result.success(projectData);
  }

  /**
   * 表单填写
   */
  @PostMapping(value = "add")
  public Result add(@RequestBody @Valid ProjectDataRequest.AddFormRequest addFormRequest, HttpServletRequest request) {
    Result result = projectDataService.addProjectData(addFormRequest.getProjId(), addFormRequest.getData(), addFormRequest.getMurmur(), addFormRequest.getTimeUse(), request);
    return Result.success(result);
  }

}
